package tk.uodrad.apex.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import tk.uodrad.apex.project.pojo.dto.ChargeDetailsAddNewDTO;
import tk.uodrad.apex.project.pojo.dto.ChargeDetailsUpdateDTO;
import tk.uodrad.apex.project.pojo.entity.AssetEquipment;
import tk.uodrad.apex.project.pojo.entity.ChargeDetails;
import tk.uodrad.apex.project.pojo.vo.*;
import tk.uodrad.apex.project.service.ChargeDetailsService;
import tk.uodrad.apex.project.web.JsonResult;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 说明：
 */
@Slf4j
@RestController
@RequestMapping("/chargeDetails")
@Transactional
public class ChargeDetailsController {
    @Autowired
    private ChargeDetailsService chargeDetailsService;

    /**
     * 添加收费明细
     * @param chargeDetailsAddNewDTO 添加收费明细DTO
     * */
    @PostMapping("/add")
    public JsonResult<String> add(@RequestBody ChargeDetailsAddNewDTO chargeDetailsAddNewDTO) {
        chargeDetailsService.save(chargeDetailsAddNewDTO);
        return JsonResult.ok("添加成功");
    }
    /**
     * 根据ID查询收费明细
     * @param id ID
     * */
    @GetMapping("/select/{id}")
    public JsonResult<ChargeDetails> selectById(@PathVariable Long id){
        ChargeDetails data = chargeDetailsService.selectById(id);
        return JsonResult.ok(data);
    }
    /**
     * 根据ID数组删除
     * @param ids ID数组
     * */
    @GetMapping("/delete")
    public JsonResult<String> deleteById(Long[] ids) {
        chargeDetailsService.removeByIds(Arrays.asList(ids));
        return JsonResult.ok("删除成功！");
    }

    /**
     * 根据ID修改收费明细信息
     * @param chargeDetailsUpdateDTO 修改收费明细DTO
     * */
    @PostMapping("/update")
    public JsonResult<String> update(@RequestBody ChargeDetailsUpdateDTO chargeDetailsUpdateDTO) {
        chargeDetailsService.updateById(chargeDetailsUpdateDTO);
        return JsonResult.ok("修改成功！");
    }

    /**
     * 分页查询收费明细列表
     * @param pageNum 第几页
     * @param pageSize 每页多少条数据
     * @param communityCode 小区编号
     * @return IPage<ChargeDetailsListVO> ChargeDetailsListVO分页对象
     * */
    @GetMapping("/list")
    public JsonResult<IPage<ChargeDetailsListVO>> list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                       @RequestParam(value = "communityCode", required = false) String communityCode) {
        IPage<ChargeDetailsListVO> list = chargeDetailsService.list(pageNum, pageSize, communityCode);
        return JsonResult.ok(list);
    }

    /**
     *
     * @return IPage<People> 分页对象
     * */
    @GetMapping("/listAmount")
    public JsonResult<List<ChargeDetailsAmountVO>> listAmount() {
        List<ChargeDetailsAmountVO> chargeDetailsAmountVOS = chargeDetailsService.listAmount();
        return JsonResult.ok(chargeDetailsAmountVOS);
    }

    @GetMapping("/listDashboard")
    public JsonResult<List<ChargeDetailsDashboardVO>> listDashboard() {
        List<ChargeDetailsDashboardVO> chargeDetailsDashboardVOS = chargeDetailsService.listDashboard();
        return JsonResult.ok(chargeDetailsDashboardVOS);
    }
}
